<?php


/**
 * Base class that represents a row from the 'users' table.
 *
 *
 *
 * @package    propel.generator..om
 */
abstract class BaseUsers extends BaseObject implements Persistent
{
    /**
     * Peer class name
     */
    const PEER = 'UsersPeer';

    /**
     * The Peer class.
     * Instance provides a convenient way of calling static methods on a class
     * that calling code may not be able to identify.
     * @var        UsersPeer
     */
    protected static $peer;

    /**
     * The flag var to prevent infinit loop in deep copy
     * @var       boolean
     */
    protected $startCopy = false;

    /**
     * The value for the id field.
     * @var        int
     */
    protected $id;

    /**
     * The value for the user_group_id field.
     * @var        int
     */
    protected $user_group_id;

    /**
     * The value for the fname field.
     * @var        string
     */
    protected $fname;

    /**
     * The value for the lname field.
     * @var        string
     */
    protected $lname;

    /**
     * The value for the email field.
     * @var        string
     */
    protected $email;

    /**
     * The value for the optional_email field.
     * @var        string
     */
    protected $optional_email;

    /**
     * The value for the company field.
     * @var        string
     */
    protected $company;

    /**
     * The value for the department field.
     * @var        string
     */
    protected $department;

    /**
     * The value for the phone field.
     * @var        string
     */
    protected $phone;

    /**
     * The value for the mobile field.
     * @var        string
     */
    protected $mobile;

    /**
     * The value for the photo field.
     * @var        string
     */
    protected $photo;

    /**
     * The value for the ad_login field.
     * @var        string
     */
    protected $ad_login;

    /**
     * The value for the role field.
     * Note: this column has a database default value of: 0
     * @var        int
     */
    protected $role;

    /**
     * The value for the deleted field.
     * Note: this column has a database default value of: '2014-04-25 17:06:21'
     * @var        string
     */
    protected $deleted;

    /**
     * The value for the active field.
     * Note: this column has a database default value of: 1
     * @var        int
     */
    protected $active;

    /**
     * The value for the last_modified field.
     * @var        string
     */
    protected $last_modified;

    /**
     * The value for the created field.
     * Note: this column has a database default value of: '2014-04-25 17:06:21'
     * @var        string
     */
    protected $created;

    /**
     * @var        UserGroups
     */
    protected $aUserGroups;

    /**
     * @var        PropelObjectCollection|AuthHistory[] Collection to store aggregation of AuthHistory objects.
     */
    protected $collAuthHistorys;
    protected $collAuthHistorysPartial;

    /**
     * @var        PropelObjectCollection|UserPulpit[] Collection to store aggregation of UserPulpit objects.
     */
    protected $collUserPulpits;
    protected $collUserPulpitsPartial;

    /**
     * @var        PropelObjectCollection|UserApplicationData[] Collection to store aggregation of UserApplicationData objects.
     */
    protected $collUserApplicationDatas;
    protected $collUserApplicationDatasPartial;

    /**
     * Flag to prevent endless save loop, if this object is referenced
     * by another object which falls in this transaction.
     * @var        boolean
     */
    protected $alreadyInSave = false;

    /**
     * Flag to prevent endless validation loop, if this object is referenced
     * by another object which falls in this transaction.
     * @var        boolean
     */
    protected $alreadyInValidation = false;

    /**
     * An array of objects scheduled for deletion.
     * @var		PropelObjectCollection
     */
    protected $authHistorysScheduledForDeletion = null;

    /**
     * An array of objects scheduled for deletion.
     * @var		PropelObjectCollection
     */
    protected $userPulpitsScheduledForDeletion = null;

    /**
     * An array of objects scheduled for deletion.
     * @var		PropelObjectCollection
     */
    protected $userApplicationDatasScheduledForDeletion = null;

    /**
     * Applies default values to this object.
     * This method should be called from the object's constructor (or
     * equivalent initialization method).
     * @see        __construct()
     */
    public function applyDefaultValues()
    {
        $this->role = 0;
        $this->deleted = '2014-04-25 17:06:21';
        $this->active = 1;
        $this->created = '2014-04-25 17:06:21';
    }

    /**
     * Initializes internal state of BaseUsers object.
     * @see        applyDefaults()
     */
    public function __construct()
    {
        parent::__construct();
        $this->applyDefaultValues();
    }

    /**
     * Get the [id] column value.
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Get the [user_group_id] column value.
     *
     * @return int
     */
    public function getUserGroupId()
    {
        return $this->user_group_id;
    }

    /**
     * Get the [fname] column value.
     *
     * @return string
     */
    public function getFname()
    {
        return $this->fname;
    }

    /**
     * Get the [lname] column value.
     *
     * @return string
     */
    public function getLname()
    {
        return $this->lname;
    }

    /**
     * Get the [email] column value.
     *
     * @return string
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Get the [optional_email] column value.
     *
     * @return string
     */
    public function getOptionalEmail()
    {
        return $this->optional_email;
    }

    /**
     * Get the [company] column value.
     *
     * @return string
     */
    public function getCompany()
    {
        return $this->company;
    }

    /**
     * Get the [department] column value.
     *
     * @return string
     */
    public function getDepartment()
    {
        return $this->department;
    }

    /**
     * Get the [phone] column value.
     *
     * @return string
     */
    public function getPhone()
    {
        return $this->phone;
    }

    /**
     * Get the [mobile] column value.
     *
     * @return string
     */
    public function getMobile()
    {
        return $this->mobile;
    }

    /**
     * Get the [photo] column value.
     *
     * @return string
     */
    public function getPhoto()
    {
        return $this->photo;
    }

    /**
     * Get the [ad_login] column value.
     *
     * @return string
     */
    public function getAdLogin()
    {
        return $this->ad_login;
    }

    /**
     * Get the [role] column value.
     *
     * @return int
     */
    public function getRole()
    {
        return $this->role;
    }

    /**
     * Get the [optionally formatted] temporal [deleted] column value.
     *
     *
     * @param string $format The date/time format string (either date()-style or strftime()-style).
     *				 If format is null, then the raw DateTime object will be returned.
     * @return mixed Formatted date/time value as string or DateTime object (if format is null), null if column is null
     * @throws PropelException - if unable to parse/validate the date/time value.
     */
    public function getDeleted($format = 'Y-m-d H:i:s')
    {
        if ($this->deleted === null) {
            return null;
        }


        try {
            $dt = new DateTime($this->deleted);
        } catch (Exception $x) {
            throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->deleted, true), $x);
        }

        if ($format === null) {
            // Because propel.useDateTimeClass is true, we return a DateTime object.
            return $dt;
        } elseif (strpos($format, '%') !== false) {
            return strftime($format, $dt->format('U'));
        } else {
            return $dt->format($format);
        }
    }

    /**
     * Get the [active] column value.
     *
     * @return int
     */
    public function getActive()
    {
        return $this->active;
    }

    /**
     * Get the [optionally formatted] temporal [last_modified] column value.
     *
     *
     * @param string $format The date/time format string (either date()-style or strftime()-style).
     *				 If format is null, then the raw DateTime object will be returned.
     * @return mixed Formatted date/time value as string or DateTime object (if format is null), null if column is null
     * @throws PropelException - if unable to parse/validate the date/time value.
     */
    public function getLastModified($format = 'Y-m-d H:i:s')
    {
        if ($this->last_modified === null) {
            return null;
        }


        try {
            $dt = new DateTime($this->last_modified);
        } catch (Exception $x) {
            throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->last_modified, true), $x);
        }

        if ($format === null) {
            // Because propel.useDateTimeClass is true, we return a DateTime object.
            return $dt;
        } elseif (strpos($format, '%') !== false) {
            return strftime($format, $dt->format('U'));
        } else {
            return $dt->format($format);
        }
    }

    /**
     * Get the [optionally formatted] temporal [created] column value.
     *
     *
     * @param string $format The date/time format string (either date()-style or strftime()-style).
     *				 If format is null, then the raw DateTime object will be returned.
     * @return mixed Formatted date/time value as string or DateTime object (if format is null), null if column is null
     * @throws PropelException - if unable to parse/validate the date/time value.
     */
    public function getCreated($format = 'Y-m-d H:i:s')
    {
        if ($this->created === null) {
            return null;
        }


        try {
            $dt = new DateTime($this->created);
        } catch (Exception $x) {
            throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created, true), $x);
        }

        if ($format === null) {
            // Because propel.useDateTimeClass is true, we return a DateTime object.
            return $dt;
        } elseif (strpos($format, '%') !== false) {
            return strftime($format, $dt->format('U'));
        } else {
            return $dt->format($format);
        }
    }

    /**
     * Set the value of [id] column.
     *
     * @param int $v new value
     * @return Users The current object (for fluent API support)
     */
    public function setId($v)
    {
        if ($v !== null) {
            $v = (int) $v;
        }

        if ($this->id !== $v) {
            $this->id = $v;
            $this->modifiedColumns[] = UsersPeer::ID;
        }


        return $this;
    } // setId()

    /**
     * Set the value of [user_group_id] column.
     *
     * @param int $v new value
     * @return Users The current object (for fluent API support)
     */
    public function setUserGroupId($v)
    {
        if ($v !== null) {
            $v = (int) $v;
        }

        if ($this->user_group_id !== $v) {
            $this->user_group_id = $v;
            $this->modifiedColumns[] = UsersPeer::USER_GROUP_ID;
        }

        if ($this->aUserGroups !== null && $this->aUserGroups->getId() !== $v) {
            $this->aUserGroups = null;
        }


        return $this;
    } // setUserGroupId()

    /**
     * Set the value of [fname] column.
     *
     * @param string $v new value
     * @return Users The current object (for fluent API support)
     */
    public function setFname($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->fname !== $v) {
            $this->fname = $v;
            $this->modifiedColumns[] = UsersPeer::FNAME;
        }


        return $this;
    } // setFname()

    /**
     * Set the value of [lname] column.
     *
     * @param string $v new value
     * @return Users The current object (for fluent API support)
     */
    public function setLname($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->lname !== $v) {
            $this->lname = $v;
            $this->modifiedColumns[] = UsersPeer::LNAME;
        }


        return $this;
    } // setLname()

    /**
     * Set the value of [email] column.
     *
     * @param string $v new value
     * @return Users The current object (for fluent API support)
     */
    public function setEmail($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->email !== $v) {
            $this->email = $v;
            $this->modifiedColumns[] = UsersPeer::EMAIL;
        }


        return $this;
    } // setEmail()

    /**
     * Set the value of [optional_email] column.
     *
     * @param string $v new value
     * @return Users The current object (for fluent API support)
     */
    public function setOptionalEmail($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->optional_email !== $v) {
            $this->optional_email = $v;
            $this->modifiedColumns[] = UsersPeer::OPTIONAL_EMAIL;
        }


        return $this;
    } // setOptionalEmail()

    /**
     * Set the value of [company] column.
     *
     * @param string $v new value
     * @return Users The current object (for fluent API support)
     */
    public function setCompany($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->company !== $v) {
            $this->company = $v;
            $this->modifiedColumns[] = UsersPeer::COMPANY;
        }


        return $this;
    } // setCompany()

    /**
     * Set the value of [department] column.
     *
     * @param string $v new value
     * @return Users The current object (for fluent API support)
     */
    public function setDepartment($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->department !== $v) {
            $this->department = $v;
            $this->modifiedColumns[] = UsersPeer::DEPARTMENT;
        }


        return $this;
    } // setDepartment()

    /**
     * Set the value of [phone] column.
     *
     * @param string $v new value
     * @return Users The current object (for fluent API support)
     */
    public function setPhone($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->phone !== $v) {
            $this->phone = $v;
            $this->modifiedColumns[] = UsersPeer::PHONE;
        }


        return $this;
    } // setPhone()

    /**
     * Set the value of [mobile] column.
     *
     * @param string $v new value
     * @return Users The current object (for fluent API support)
     */
    public function setMobile($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->mobile !== $v) {
            $this->mobile = $v;
            $this->modifiedColumns[] = UsersPeer::MOBILE;
        }


        return $this;
    } // setMobile()

    /**
     * Set the value of [photo] column.
     *
     * @param string $v new value
     * @return Users The current object (for fluent API support)
     */
    public function setPhoto($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->photo !== $v) {
            $this->photo = $v;
            $this->modifiedColumns[] = UsersPeer::PHOTO;
        }


        return $this;
    } // setPhoto()

    /**
     * Set the value of [ad_login] column.
     *
     * @param string $v new value
     * @return Users The current object (for fluent API support)
     */
    public function setAdLogin($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->ad_login !== $v) {
            $this->ad_login = $v;
            $this->modifiedColumns[] = UsersPeer::AD_LOGIN;
        }


        return $this;
    } // setAdLogin()

    /**
     * Set the value of [role] column.
     *
     * @param int $v new value
     * @return Users The current object (for fluent API support)
     */
    public function setRole($v)
    {
        if ($v !== null) {
            $v = (int) $v;
        }

        if ($this->role !== $v) {
            $this->role = $v;
            $this->modifiedColumns[] = UsersPeer::ROLE;
        }


        return $this;
    } // setRole()

    /**
     * Sets the value of [deleted] column to a normalized version of the date/time value specified.
     *
     * @param mixed $v string, integer (timestamp), or DateTime value.
     *               Empty strings are treated as null.
     * @return Users The current object (for fluent API support)
     */
    public function setDeleted($v)
    {
        $dt = PropelDateTime::newInstance($v, null, 'DateTime');
        if ($this->deleted !== null || $dt !== null) {
            $currentDateAsString = ($this->deleted !== null && $tmpDt = new DateTime($this->deleted)) ? $tmpDt->format('Y-m-d H:i:s') : null;
            $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
            if ( ($currentDateAsString !== $newDateAsString) // normalized values don't match
                || ($dt->format('Y-m-d H:i:s') === '2014-04-25 17:06:21') // or the entered value matches the default
                 ) {
                $this->deleted = $newDateAsString;
                $this->modifiedColumns[] = UsersPeer::DELETED;
            }
        } // if either are not null


        return $this;
    } // setDeleted()

    /**
     * Set the value of [active] column.
     *
     * @param int $v new value
     * @return Users The current object (for fluent API support)
     */
    public function setActive($v)
    {
        if ($v !== null) {
            $v = (int) $v;
        }

        if ($this->active !== $v) {
            $this->active = $v;
            $this->modifiedColumns[] = UsersPeer::ACTIVE;
        }


        return $this;
    } // setActive()

    /**
     * Sets the value of [last_modified] column to a normalized version of the date/time value specified.
     *
     * @param mixed $v string, integer (timestamp), or DateTime value.
     *               Empty strings are treated as null.
     * @return Users The current object (for fluent API support)
     */
    public function setLastModified($v)
    {
        $dt = PropelDateTime::newInstance($v, null, 'DateTime');
        if ($this->last_modified !== null || $dt !== null) {
            $currentDateAsString = ($this->last_modified !== null && $tmpDt = new DateTime($this->last_modified)) ? $tmpDt->format('Y-m-d H:i:s') : null;
            $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
            if ($currentDateAsString !== $newDateAsString) {
                $this->last_modified = $newDateAsString;
                $this->modifiedColumns[] = UsersPeer::LAST_MODIFIED;
            }
        } // if either are not null


        return $this;
    } // setLastModified()

    /**
     * Sets the value of [created] column to a normalized version of the date/time value specified.
     *
     * @param mixed $v string, integer (timestamp), or DateTime value.
     *               Empty strings are treated as null.
     * @return Users The current object (for fluent API support)
     */
    public function setCreated($v)
    {
        $dt = PropelDateTime::newInstance($v, null, 'DateTime');
        if ($this->created !== null || $dt !== null) {
            $currentDateAsString = ($this->created !== null && $tmpDt = new DateTime($this->created)) ? $tmpDt->format('Y-m-d H:i:s') : null;
            $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
            if ( ($currentDateAsString !== $newDateAsString) // normalized values don't match
                || ($dt->format('Y-m-d H:i:s') === '2014-04-25 17:06:21') // or the entered value matches the default
                 ) {
                $this->created = $newDateAsString;
                $this->modifiedColumns[] = UsersPeer::CREATED;
            }
        } // if either are not null


        return $this;
    } // setCreated()

    /**
     * Indicates whether the columns in this object are only set to default values.
     *
     * This method can be used in conjunction with isModified() to indicate whether an object is both
     * modified _and_ has some values set which are non-default.
     *
     * @return boolean Whether the columns in this object are only been set with default values.
     */
    public function hasOnlyDefaultValues()
    {
            if ($this->role !== 0) {
                return false;
            }

            if ($this->deleted !== '2014-04-25 17:06:21') {
                return false;
            }

            if ($this->active !== 1) {
                return false;
            }

            if ($this->created !== '2014-04-25 17:06:21') {
                return false;
            }

        // otherwise, everything was equal, so return true
        return true;
    } // hasOnlyDefaultValues()

    /**
     * Hydrates (populates) the object variables with values from the database resultset.
     *
     * An offset (0-based "start column") is specified so that objects can be hydrated
     * with a subset of the columns in the resultset rows.  This is needed, for example,
     * for results of JOIN queries where the resultset row includes columns from two or
     * more tables.
     *
     * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
     * @param int $startcol 0-based offset column which indicates which restultset column to start with.
     * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
     * @return int             next starting column
     * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
     */
    public function hydrate($row, $startcol = 0, $rehydrate = false)
    {
        try {

            $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
            $this->user_group_id = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
            $this->fname = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
            $this->lname = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
            $this->email = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
            $this->optional_email = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
            $this->company = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null;
            $this->department = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null;
            $this->phone = ($row[$startcol + 8] !== null) ? (string) $row[$startcol + 8] : null;
            $this->mobile = ($row[$startcol + 9] !== null) ? (string) $row[$startcol + 9] : null;
            $this->photo = ($row[$startcol + 10] !== null) ? (string) $row[$startcol + 10] : null;
            $this->ad_login = ($row[$startcol + 11] !== null) ? (string) $row[$startcol + 11] : null;
            $this->role = ($row[$startcol + 12] !== null) ? (int) $row[$startcol + 12] : null;
            $this->deleted = ($row[$startcol + 13] !== null) ? (string) $row[$startcol + 13] : null;
            $this->active = ($row[$startcol + 14] !== null) ? (int) $row[$startcol + 14] : null;
            $this->last_modified = ($row[$startcol + 15] !== null) ? (string) $row[$startcol + 15] : null;
            $this->created = ($row[$startcol + 16] !== null) ? (string) $row[$startcol + 16] : null;
            $this->resetModified();

            $this->setNew(false);

            if ($rehydrate) {
                $this->ensureConsistency();
            }

            return $startcol + 17; // 17 = UsersPeer::NUM_HYDRATE_COLUMNS.

        } catch (Exception $e) {
            throw new PropelException("Error populating Users object", $e);
        }
    }

    /**
     * Checks and repairs the internal consistency of the object.
     *
     * This method is executed after an already-instantiated object is re-hydrated
     * from the database.  It exists to check any foreign keys to make sure that
     * the objects related to the current object are correct based on foreign key.
     *
     * You can override this method in the stub class, but you should always invoke
     * the base method from the overridden method (i.e. parent::ensureConsistency()),
     * in case your model changes.
     *
     * @throws PropelException
     */
    public function ensureConsistency()
    {

        if ($this->aUserGroups !== null && $this->user_group_id !== $this->aUserGroups->getId()) {
            $this->aUserGroups = null;
        }
    } // ensureConsistency

    /**
     * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
     *
     * This will only work if the object has been saved and has a valid primary key set.
     *
     * @param boolean $deep (optional) Whether to also de-associated any related objects.
     * @param PropelPDO $con (optional) The PropelPDO connection to use.
     * @return void
     * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
     */
    public function reload($deep = false, PropelPDO $con = null)
    {
        if ($this->isDeleted()) {
            throw new PropelException("Cannot reload a deleted object.");
        }

        if ($this->isNew()) {
            throw new PropelException("Cannot reload an unsaved object.");
        }

        if ($con === null) {
            $con = Propel::getConnection(UsersPeer::DATABASE_NAME, Propel::CONNECTION_READ);
        }

        // We don't need to alter the object instance pool; we're just modifying this instance
        // already in the pool.

        $stmt = UsersPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
        $row = $stmt->fetch(PDO::FETCH_NUM);
        $stmt->closeCursor();
        if (!$row) {
            throw new PropelException('Cannot find matching row in the database to reload object values.');
        }
        $this->hydrate($row, 0, true); // rehydrate

        if ($deep) {  // also de-associate any related objects?

            $this->aUserGroups = null;
            $this->collAuthHistorys = null;

            $this->collUserPulpits = null;

            $this->collUserApplicationDatas = null;

        } // if (deep)
    }

    /**
     * Removes this object from datastore and sets delete attribute.
     *
     * @param PropelPDO $con
     * @return void
     * @throws PropelException
     * @throws Exception
     * @see        BaseObject::setDeleted()
     * @see        BaseObject::isDeleted()
     */
    public function delete(PropelPDO $con = null)
    {
        if ($this->isDeleted()) {
            throw new PropelException("This object has already been deleted.");
        }

        if ($con === null) {
            $con = Propel::getConnection(UsersPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
        }

        $con->beginTransaction();
        try {
            $deleteQuery = UsersQuery::create()
                ->filterByPrimaryKey($this->getPrimaryKey());
            $ret = $this->preDelete($con);
            if ($ret) {
                $deleteQuery->delete($con);
                $this->postDelete($con);
                $con->commit();
                $this->setDeleted(true);
            } else {
                $con->commit();
            }
        } catch (Exception $e) {
            $con->rollBack();
            throw $e;
        }
    }

    /**
     * Persists this object to the database.
     *
     * If the object is new, it inserts it; otherwise an update is performed.
     * All modified related objects will also be persisted in the doSave()
     * method.  This method wraps all precipitate database operations in a
     * single transaction.
     *
     * @param PropelPDO $con
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
     * @throws PropelException
     * @throws Exception
     * @see        doSave()
     */
    public function save(PropelPDO $con = null)
    {
        if ($this->isDeleted()) {
            throw new PropelException("You cannot save an object that has been deleted.");
        }

        if ($con === null) {
            $con = Propel::getConnection(UsersPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
        }

        $con->beginTransaction();
        $isInsert = $this->isNew();
        try {
            $ret = $this->preSave($con);
            if ($isInsert) {
                $ret = $ret && $this->preInsert($con);
            } else {
                $ret = $ret && $this->preUpdate($con);
            }
            if ($ret) {
                $affectedRows = $this->doSave($con);
                if ($isInsert) {
                    $this->postInsert($con);
                } else {
                    $this->postUpdate($con);
                }
                $this->postSave($con);
                UsersPeer::addInstanceToPool($this);
            } else {
                $affectedRows = 0;
            }
            $con->commit();

            return $affectedRows;
        } catch (Exception $e) {
            $con->rollBack();
            throw $e;
        }
    }

    /**
     * Performs the work of inserting or updating the row in the database.
     *
     * If the object is new, it inserts it; otherwise an update is performed.
     * All related objects are also updated in this method.
     *
     * @param PropelPDO $con
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
     * @throws PropelException
     * @see        save()
     */
    protected function doSave(PropelPDO $con)
    {
        $affectedRows = 0; // initialize var to track total num of affected rows
        if (!$this->alreadyInSave) {
            $this->alreadyInSave = true;

            // We call the save method on the following object(s) if they
            // were passed to this object by their coresponding set
            // method.  This object relates to these object(s) by a
            // foreign key reference.

            if ($this->aUserGroups !== null) {
                if ($this->aUserGroups->isModified() || $this->aUserGroups->isNew()) {
                    $affectedRows += $this->aUserGroups->save($con);
                }
                $this->setUserGroups($this->aUserGroups);
            }

            if ($this->isNew() || $this->isModified()) {
                // persist changes
                if ($this->isNew()) {
                    $this->doInsert($con);
                } else {
                    $this->doUpdate($con);
                }
                $affectedRows += 1;
                $this->resetModified();
            }

            if ($this->authHistorysScheduledForDeletion !== null) {
                if (!$this->authHistorysScheduledForDeletion->isEmpty()) {
                    foreach ($this->authHistorysScheduledForDeletion as $authHistory) {
                        // need to save related object because we set the relation to null
                        $authHistory->save($con);
                    }
                    $this->authHistorysScheduledForDeletion = null;
                }
            }

            if ($this->collAuthHistorys !== null) {
                foreach ($this->collAuthHistorys as $referrerFK) {
                    if (!$referrerFK->isDeleted()) {
                        $affectedRows += $referrerFK->save($con);
                    }
                }
            }

            if ($this->userPulpitsScheduledForDeletion !== null) {
                if (!$this->userPulpitsScheduledForDeletion->isEmpty()) {
                    UserPulpitQuery::create()
                        ->filterByPrimaryKeys($this->userPulpitsScheduledForDeletion->getPrimaryKeys(false))
                        ->delete($con);
                    $this->userPulpitsScheduledForDeletion = null;
                }
            }

            if ($this->collUserPulpits !== null) {
                foreach ($this->collUserPulpits as $referrerFK) {
                    if (!$referrerFK->isDeleted()) {
                        $affectedRows += $referrerFK->save($con);
                    }
                }
            }

            if ($this->userApplicationDatasScheduledForDeletion !== null) {
                if (!$this->userApplicationDatasScheduledForDeletion->isEmpty()) {
                    UserApplicationDataQuery::create()
                        ->filterByPrimaryKeys($this->userApplicationDatasScheduledForDeletion->getPrimaryKeys(false))
                        ->delete($con);
                    $this->userApplicationDatasScheduledForDeletion = null;
                }
            }

            if ($this->collUserApplicationDatas !== null) {
                foreach ($this->collUserApplicationDatas as $referrerFK) {
                    if (!$referrerFK->isDeleted()) {
                        $affectedRows += $referrerFK->save($con);
                    }
                }
            }

            $this->alreadyInSave = false;

        }

        return $affectedRows;
    } // doSave()

    /**
     * Insert the row in the database.
     *
     * @param PropelPDO $con
     *
     * @throws PropelException
     * @see        doSave()
     */
    protected function doInsert(PropelPDO $con)
    {
        $this->modifiedColumns[] = UsersPeer::ID;
        $criteria = $this->buildCriteria();
        if ($criteria->keyContainsValue(UsersPeer::ID) ) {
            throw new PropelException('Cannot insert a value for auto-increment primary key (' . UsersPeer::ID . ')');
        }
        // remove pkey col since this table uses auto-increment and passing a null value for it is not valid
        $criteria->remove(UsersPeer::ID);
        $pk = BasePeer::doInsert($criteria, $con);
        $this->setId($pk);  //[IMV] update autoincrement primary key
        $this->setNew(false);
    }

    /**
     * Update the row in the database.
     *
     * @param PropelPDO $con
     *
     * @see        doSave()
     */
    protected function doUpdate(PropelPDO $con)
    {
        $selectCriteria = $this->buildPkeyCriteria();
        $valuesCriteria = $this->buildCriteria();
        BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
    }

    /**
     * Array of ValidationFailed objects.
     * @var        array ValidationFailed[]
     */
    protected $validationFailures = array();

    /**
     * Gets any ValidationFailed objects that resulted from last call to validate().
     *
     *
     * @return array ValidationFailed[]
     * @see        validate()
     */
    public function getValidationFailures()
    {
        return $this->validationFailures;
    }

    /**
     * Validates the objects modified field values and all objects related to this table.
     *
     * If $columns is either a column name or an array of column names
     * only those columns are validated.
     *
     * @param mixed $columns Column name or an array of column names.
     * @return boolean Whether all columns pass validation.
     * @see        doValidate()
     * @see        getValidationFailures()
     */
    public function validate($columns = null)
    {
        $res = $this->doValidate($columns);
        if ($res === true) {
            $this->validationFailures = array();

            return true;
        } else {
            $this->validationFailures = $res;

            return false;
        }
    }

    /**
     * This function performs the validation work for complex object models.
     *
     * In addition to checking the current object, all related objects will
     * also be validated.  If all pass then <code>true</code> is returned; otherwise
     * an aggreagated array of ValidationFailed objects will be returned.
     *
     * @param array $columns Array of column names to validate.
     * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
     */
    protected function doValidate($columns = null)
    {
        if (!$this->alreadyInValidation) {
            $this->alreadyInValidation = true;
            $retval = null;

            $failureMap = array();


            // We call the validate method on the following object(s) if they
            // were passed to this object by their coresponding set
            // method.  This object relates to these object(s) by a
            // foreign key reference.

            if ($this->aUserGroups !== null) {
                if (!$this->aUserGroups->validate($columns)) {
                    $failureMap = array_merge($failureMap, $this->aUserGroups->getValidationFailures());
                }
            }


            if (($retval = UsersPeer::doValidate($this, $columns)) !== true) {
                $failureMap = array_merge($failureMap, $retval);
            }


                if ($this->collAuthHistorys !== null) {
                    foreach ($this->collAuthHistorys as $referrerFK) {
                        if (!$referrerFK->validate($columns)) {
                            $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                        }
                    }
                }

                if ($this->collUserPulpits !== null) {
                    foreach ($this->collUserPulpits as $referrerFK) {
                        if (!$referrerFK->validate($columns)) {
                            $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                        }
                    }
                }

                if ($this->collUserApplicationDatas !== null) {
                    foreach ($this->collUserApplicationDatas as $referrerFK) {
                        if (!$referrerFK->validate($columns)) {
                            $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                        }
                    }
                }


            $this->alreadyInValidation = false;
        }

        return (!empty($failureMap) ? $failureMap : true);
    }

    /**
     * Retrieves a field from the object by name passed in as a string.
     *
     * @param string $name name
     * @param string $type The type of fieldname the $name is of:
     *               one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     *               BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     *               Defaults to BasePeer::TYPE_PHPNAME
     * @return mixed Value of field.
     */
    public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
    {
        $pos = UsersPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
        $field = $this->getByPosition($pos);

        return $field;
    }

    /**
     * Retrieves a field from the object by Position as specified in the xml schema.
     * Zero-based.
     *
     * @param int $pos position in xml schema
     * @return mixed Value of field at $pos
     */
    public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getUserGroupId();
                break;
            case 2:
                return $this->getFname();
                break;
            case 3:
                return $this->getLname();
                break;
            case 4:
                return $this->getEmail();
                break;
            case 5:
                return $this->getOptionalEmail();
                break;
            case 6:
                return $this->getCompany();
                break;
            case 7:
                return $this->getDepartment();
                break;
            case 8:
                return $this->getPhone();
                break;
            case 9:
                return $this->getMobile();
                break;
            case 10:
                return $this->getPhoto();
                break;
            case 11:
                return $this->getAdLogin();
                break;
            case 12:
                return $this->getRole();
                break;
            case 13:
                return $this->getDeleted();
                break;
            case 14:
                return $this->getActive();
                break;
            case 15:
                return $this->getLastModified();
                break;
            case 16:
                return $this->getCreated();
                break;
            default:
                return null;
                break;
        } // switch()
    }

    /**
     * Exports the object as an array.
     *
     * You can specify the key type of the array by passing one of the class
     * type constants.
     *
     * @param     string  $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
     *                    BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     *                    Defaults to BasePeer::TYPE_PHPNAME.
     * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
     * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
     * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
     *
     * @return array an associative array containing the field names (as keys) and field values
     */
    public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
    {
        if (isset($alreadyDumpedObjects['Users'][$this->getPrimaryKey()])) {
            return '*RECURSION*';
        }
        $alreadyDumpedObjects['Users'][$this->getPrimaryKey()] = true;
        $keys = UsersPeer::getFieldNames($keyType);
        $result = array(
            $keys[0] => $this->getId(),
            $keys[1] => $this->getUserGroupId(),
            $keys[2] => $this->getFname(),
            $keys[3] => $this->getLname(),
            $keys[4] => $this->getEmail(),
            $keys[5] => $this->getOptionalEmail(),
            $keys[6] => $this->getCompany(),
            $keys[7] => $this->getDepartment(),
            $keys[8] => $this->getPhone(),
            $keys[9] => $this->getMobile(),
            $keys[10] => $this->getPhoto(),
            $keys[11] => $this->getAdLogin(),
            $keys[12] => $this->getRole(),
            $keys[13] => $this->getDeleted(),
            $keys[14] => $this->getActive(),
            $keys[15] => $this->getLastModified(),
            $keys[16] => $this->getCreated(),
        );
        if ($includeForeignObjects) {
            if (null !== $this->aUserGroups) {
                $result['UserGroups'] = $this->aUserGroups->toArray($keyType, $includeLazyLoadColumns,  $alreadyDumpedObjects, true);
            }
            if (null !== $this->collAuthHistorys) {
                $result['AuthHistorys'] = $this->collAuthHistorys->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
            }
            if (null !== $this->collUserPulpits) {
                $result['UserPulpits'] = $this->collUserPulpits->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
            }
            if (null !== $this->collUserApplicationDatas) {
                $result['UserApplicationDatas'] = $this->collUserApplicationDatas->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
            }
        }

        return $result;
    }

    /**
     * Sets a field from the object by name passed in as a string.
     *
     * @param string $name peer name
     * @param mixed $value field value
     * @param string $type The type of fieldname the $name is of:
     *                     one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     *                     BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     *                     Defaults to BasePeer::TYPE_PHPNAME
     * @return void
     */
    public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
    {
        $pos = UsersPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);

        $this->setByPosition($pos, $value);
    }

    /**
     * Sets a field from the object by Position as specified in the xml schema.
     * Zero-based.
     *
     * @param int $pos position in xml schema
     * @param mixed $value field value
     * @return void
     */
    public function setByPosition($pos, $value)
    {
        switch ($pos) {
            case 0:
                $this->setId($value);
                break;
            case 1:
                $this->setUserGroupId($value);
                break;
            case 2:
                $this->setFname($value);
                break;
            case 3:
                $this->setLname($value);
                break;
            case 4:
                $this->setEmail($value);
                break;
            case 5:
                $this->setOptionalEmail($value);
                break;
            case 6:
                $this->setCompany($value);
                break;
            case 7:
                $this->setDepartment($value);
                break;
            case 8:
                $this->setPhone($value);
                break;
            case 9:
                $this->setMobile($value);
                break;
            case 10:
                $this->setPhoto($value);
                break;
            case 11:
                $this->setAdLogin($value);
                break;
            case 12:
                $this->setRole($value);
                break;
            case 13:
                $this->setDeleted($value);
                break;
            case 14:
                $this->setActive($value);
                break;
            case 15:
                $this->setLastModified($value);
                break;
            case 16:
                $this->setCreated($value);
                break;
        } // switch()
    }

    /**
     * Populates the object using an array.
     *
     * This is particularly useful when populating an object from one of the
     * request arrays (e.g. $_POST).  This method goes through the column
     * names, checking to see whether a matching key exists in populated
     * array. If so the setByName() method is called for that column.
     *
     * You can specify the key type of the array by additionally passing one
     * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
     * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     * The default key type is the column's BasePeer::TYPE_PHPNAME
     *
     * @param array  $arr     An array to populate the object from.
     * @param string $keyType The type of keys the array uses.
     * @return void
     */
    public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
    {
        $keys = UsersPeer::getFieldNames($keyType);

        if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
        if (array_key_exists($keys[1], $arr)) $this->setUserGroupId($arr[$keys[1]]);
        if (array_key_exists($keys[2], $arr)) $this->setFname($arr[$keys[2]]);
        if (array_key_exists($keys[3], $arr)) $this->setLname($arr[$keys[3]]);
        if (array_key_exists($keys[4], $arr)) $this->setEmail($arr[$keys[4]]);
        if (array_key_exists($keys[5], $arr)) $this->setOptionalEmail($arr[$keys[5]]);
        if (array_key_exists($keys[6], $arr)) $this->setCompany($arr[$keys[6]]);
        if (array_key_exists($keys[7], $arr)) $this->setDepartment($arr[$keys[7]]);
        if (array_key_exists($keys[8], $arr)) $this->setPhone($arr[$keys[8]]);
        if (array_key_exists($keys[9], $arr)) $this->setMobile($arr[$keys[9]]);
        if (array_key_exists($keys[10], $arr)) $this->setPhoto($arr[$keys[10]]);
        if (array_key_exists($keys[11], $arr)) $this->setAdLogin($arr[$keys[11]]);
        if (array_key_exists($keys[12], $arr)) $this->setRole($arr[$keys[12]]);
        if (array_key_exists($keys[13], $arr)) $this->setDeleted($arr[$keys[13]]);
        if (array_key_exists($keys[14], $arr)) $this->setActive($arr[$keys[14]]);
        if (array_key_exists($keys[15], $arr)) $this->setLastModified($arr[$keys[15]]);
        if (array_key_exists($keys[16], $arr)) $this->setCreated($arr[$keys[16]]);
    }

    /**
     * Build a Criteria object containing the values of all modified columns in this object.
     *
     * @return Criteria The Criteria object containing all modified values.
     */
    public function buildCriteria()
    {
        $criteria = new Criteria(UsersPeer::DATABASE_NAME);

        if ($this->isColumnModified(UsersPeer::ID)) $criteria->add(UsersPeer::ID, $this->id);
        if ($this->isColumnModified(UsersPeer::USER_GROUP_ID)) $criteria->add(UsersPeer::USER_GROUP_ID, $this->user_group_id);
        if ($this->isColumnModified(UsersPeer::FNAME)) $criteria->add(UsersPeer::FNAME, $this->fname);
        if ($this->isColumnModified(UsersPeer::LNAME)) $criteria->add(UsersPeer::LNAME, $this->lname);
        if ($this->isColumnModified(UsersPeer::EMAIL)) $criteria->add(UsersPeer::EMAIL, $this->email);
        if ($this->isColumnModified(UsersPeer::OPTIONAL_EMAIL)) $criteria->add(UsersPeer::OPTIONAL_EMAIL, $this->optional_email);
        if ($this->isColumnModified(UsersPeer::COMPANY)) $criteria->add(UsersPeer::COMPANY, $this->company);
        if ($this->isColumnModified(UsersPeer::DEPARTMENT)) $criteria->add(UsersPeer::DEPARTMENT, $this->department);
        if ($this->isColumnModified(UsersPeer::PHONE)) $criteria->add(UsersPeer::PHONE, $this->phone);
        if ($this->isColumnModified(UsersPeer::MOBILE)) $criteria->add(UsersPeer::MOBILE, $this->mobile);
        if ($this->isColumnModified(UsersPeer::PHOTO)) $criteria->add(UsersPeer::PHOTO, $this->photo);
        if ($this->isColumnModified(UsersPeer::AD_LOGIN)) $criteria->add(UsersPeer::AD_LOGIN, $this->ad_login);
        if ($this->isColumnModified(UsersPeer::ROLE)) $criteria->add(UsersPeer::ROLE, $this->role);
        if ($this->isColumnModified(UsersPeer::DELETED)) $criteria->add(UsersPeer::DELETED, $this->deleted);
        if ($this->isColumnModified(UsersPeer::ACTIVE)) $criteria->add(UsersPeer::ACTIVE, $this->active);
        if ($this->isColumnModified(UsersPeer::LAST_MODIFIED)) $criteria->add(UsersPeer::LAST_MODIFIED, $this->last_modified);
        if ($this->isColumnModified(UsersPeer::CREATED)) $criteria->add(UsersPeer::CREATED, $this->created);

        return $criteria;
    }

    /**
     * Builds a Criteria object containing the primary key for this object.
     *
     * Unlike buildCriteria() this method includes the primary key values regardless
     * of whether or not they have been modified.
     *
     * @return Criteria The Criteria object containing value(s) for primary key(s).
     */
    public function buildPkeyCriteria()
    {
        $criteria = new Criteria(UsersPeer::DATABASE_NAME);
        $criteria->add(UsersPeer::ID, $this->id);

        return $criteria;
    }

    /**
     * Returns the primary key for this object (row).
     * @return int
     */
    public function getPrimaryKey()
    {
        return $this->getId();
    }

    /**
     * Generic method to set the primary key (id column).
     *
     * @param  int $key Primary key.
     * @return void
     */
    public function setPrimaryKey($key)
    {
        $this->setId($key);
    }

    /**
     * Returns true if the primary key for this object is null.
     * @return boolean
     */
    public function isPrimaryKeyNull()
    {

        return null === $this->getId();
    }

    /**
     * Sets contents of passed object to values from current object.
     *
     * If desired, this method can also make copies of all associated (fkey referrers)
     * objects.
     *
     * @param object $copyObj An object of Users (or compatible) type.
     * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
     * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new.
     * @throws PropelException
     */
    public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
    {
        $copyObj->setUserGroupId($this->getUserGroupId());
        $copyObj->setFname($this->getFname());
        $copyObj->setLname($this->getLname());
        $copyObj->setEmail($this->getEmail());
        $copyObj->setOptionalEmail($this->getOptionalEmail());
        $copyObj->setCompany($this->getCompany());
        $copyObj->setDepartment($this->getDepartment());
        $copyObj->setPhone($this->getPhone());
        $copyObj->setMobile($this->getMobile());
        $copyObj->setPhoto($this->getPhoto());
        $copyObj->setAdLogin($this->getAdLogin());
        $copyObj->setRole($this->getRole());
        $copyObj->setDeleted($this->getDeleted());
        $copyObj->setActive($this->getActive());
        $copyObj->setLastModified($this->getLastModified());
        $copyObj->setCreated($this->getCreated());

        if ($deepCopy && !$this->startCopy) {
            // important: temporarily setNew(false) because this affects the behavior of
            // the getter/setter methods for fkey referrer objects.
            $copyObj->setNew(false);
            // store object hash to prevent cycle
            $this->startCopy = true;

            foreach ($this->getAuthHistorys() as $relObj) {
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
                    $copyObj->addAuthHistory($relObj->copy($deepCopy));
                }
            }

            foreach ($this->getUserPulpits() as $relObj) {
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
                    $copyObj->addUserPulpit($relObj->copy($deepCopy));
                }
            }

            foreach ($this->getUserApplicationDatas() as $relObj) {
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
                    $copyObj->addUserApplicationData($relObj->copy($deepCopy));
                }
            }

            //unflag object copy
            $this->startCopy = false;
        } // if ($deepCopy)

        if ($makeNew) {
            $copyObj->setNew(true);
            $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
        }
    }

    /**
     * Makes a copy of this object that will be inserted as a new row in table when saved.
     * It creates a new object filling in the simple attributes, but skipping any primary
     * keys that are defined for the table.
     *
     * If desired, this method can also make copies of all associated (fkey referrers)
     * objects.
     *
     * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
     * @return Users Clone of current object.
     * @throws PropelException
     */
    public function copy($deepCopy = false)
    {
        // we use get_class(), because this might be a subclass
        $clazz = get_class($this);
        $copyObj = new $clazz();
        $this->copyInto($copyObj, $deepCopy);

        return $copyObj;
    }

    /**
     * Returns a peer instance associated with this om.
     *
     * Since Peer classes are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     *
     * @return UsersPeer
     */
    public function getPeer()
    {
        if (self::$peer === null) {
            self::$peer = new UsersPeer();
        }

        return self::$peer;
    }

    /**
     * Declares an association between this object and a UserGroups object.
     *
     * @param             UserGroups $v
     * @return Users The current object (for fluent API support)
     * @throws PropelException
     */
    public function setUserGroups(UserGroups $v = null)
    {
        if ($v === null) {
            $this->setUserGroupId(NULL);
        } else {
            $this->setUserGroupId($v->getId());
        }

        $this->aUserGroups = $v;

        // Add binding for other direction of this n:n relationship.
        // If this object has already been added to the UserGroups object, it will not be re-added.
        if ($v !== null) {
            $v->addUsers($this);
        }


        return $this;
    }


    /**
     * Get the associated UserGroups object
     *
     * @param PropelPDO $con Optional Connection object.
     * @return UserGroups The associated UserGroups object.
     * @throws PropelException
     */
    public function getUserGroups(PropelPDO $con = null)
    {
        if ($this->aUserGroups === null && ($this->user_group_id !== null)) {
            $this->aUserGroups = UserGroupsQuery::create()->findPk($this->user_group_id, $con);
            /* The following can be used additionally to
                guarantee the related object contains a reference
                to this object.  This level of coupling may, however, be
                undesirable since it could result in an only partially populated collection
                in the referenced object.
                $this->aUserGroups->addUserss($this);
             */
        }

        return $this->aUserGroups;
    }


    /**
     * Initializes a collection based on the name of a relation.
     * Avoids crafting an 'init[$relationName]s' method name
     * that wouldn't work when StandardEnglishPluralizer is used.
     *
     * @param string $relationName The name of the relation to initialize
     * @return void
     */
    public function initRelation($relationName)
    {
        if ('AuthHistory' == $relationName) {
            $this->initAuthHistorys();
        }
        if ('UserPulpit' == $relationName) {
            $this->initUserPulpits();
        }
        if ('UserApplicationData' == $relationName) {
            $this->initUserApplicationDatas();
        }
    }

    /**
     * Clears out the collAuthHistorys collection
     *
     * This does not modify the database; however, it will remove any associated objects, causing
     * them to be refetched by subsequent calls to accessor method.
     *
     * @return void
     * @see        addAuthHistorys()
     */
    public function clearAuthHistorys()
    {
        $this->collAuthHistorys = null; // important to set this to null since that means it is uninitialized
        $this->collAuthHistorysPartial = null;
    }

    /**
     * reset is the collAuthHistorys collection loaded partially
     *
     * @return void
     */
    public function resetPartialAuthHistorys($v = true)
    {
        $this->collAuthHistorysPartial = $v;
    }

    /**
     * Initializes the collAuthHistorys collection.
     *
     * By default this just sets the collAuthHistorys collection to an empty array (like clearcollAuthHistorys());
     * however, you may wish to override this method in your stub class to provide setting appropriate
     * to your application -- for example, setting the initial array to the values stored in database.
     *
     * @param boolean $overrideExisting If set to true, the method call initializes
     *                                        the collection even if it is not empty
     *
     * @return void
     */
    public function initAuthHistorys($overrideExisting = true)
    {
        if (null !== $this->collAuthHistorys && !$overrideExisting) {
            return;
        }
        $this->collAuthHistorys = new PropelObjectCollection();
        $this->collAuthHistorys->setModel('AuthHistory');
    }

    /**
     * Gets an array of AuthHistory objects which contain a foreign key that references this object.
     *
     * If the $criteria is not null, it is used to always fetch the results from the database.
     * Otherwise the results are fetched from the database the first time, then cached.
     * Next time the same method is called without $criteria, the cached collection is returned.
     * If this Users is new, it will return
     * an empty collection or the current collection; the criteria is ignored on a new object.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @return PropelObjectCollection|AuthHistory[] List of AuthHistory objects
     * @throws PropelException
     */
    public function getAuthHistorys($criteria = null, PropelPDO $con = null)
    {
        $partial = $this->collAuthHistorysPartial && !$this->isNew();
        if (null === $this->collAuthHistorys || null !== $criteria  || $partial) {
            if ($this->isNew() && null === $this->collAuthHistorys) {
                // return empty collection
                $this->initAuthHistorys();
            } else {
                $collAuthHistorys = AuthHistoryQuery::create(null, $criteria)
                    ->filterByUsers($this)
                    ->find($con);
                if (null !== $criteria) {
                    if (false !== $this->collAuthHistorysPartial && count($collAuthHistorys)) {
                      $this->initAuthHistorys(false);

                      foreach($collAuthHistorys as $obj) {
                        if (false == $this->collAuthHistorys->contains($obj)) {
                          $this->collAuthHistorys->append($obj);
                        }
                      }

                      $this->collAuthHistorysPartial = true;
                    }

                    return $collAuthHistorys;
                }

                if($partial && $this->collAuthHistorys) {
                    foreach($this->collAuthHistorys as $obj) {
                        if($obj->isNew()) {
                            $collAuthHistorys[] = $obj;
                        }
                    }
                }

                $this->collAuthHistorys = $collAuthHistorys;
                $this->collAuthHistorysPartial = false;
            }
        }

        return $this->collAuthHistorys;
    }

    /**
     * Sets a collection of AuthHistory objects related by a one-to-many relationship
     * to the current object.
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
     * and new objects from the given Propel collection.
     *
     * @param PropelCollection $authHistorys A Propel collection.
     * @param PropelPDO $con Optional connection object
     */
    public function setAuthHistorys(PropelCollection $authHistorys, PropelPDO $con = null)
    {
        $this->authHistorysScheduledForDeletion = $this->getAuthHistorys(new Criteria(), $con)->diff($authHistorys);

        foreach ($this->authHistorysScheduledForDeletion as $authHistoryRemoved) {
            $authHistoryRemoved->setUsers(null);
        }

        $this->collAuthHistorys = null;
        foreach ($authHistorys as $authHistory) {
            $this->addAuthHistory($authHistory);
        }

        $this->collAuthHistorys = $authHistorys;
        $this->collAuthHistorysPartial = false;
    }

    /**
     * Returns the number of related AuthHistory objects.
     *
     * @param Criteria $criteria
     * @param boolean $distinct
     * @param PropelPDO $con
     * @return int             Count of related AuthHistory objects.
     * @throws PropelException
     */
    public function countAuthHistorys(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    {
        $partial = $this->collAuthHistorysPartial && !$this->isNew();
        if (null === $this->collAuthHistorys || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collAuthHistorys) {
                return 0;
            } else {
                if($partial && !$criteria) {
                    return count($this->getAuthHistorys());
                }
                $query = AuthHistoryQuery::create(null, $criteria);
                if ($distinct) {
                    $query->distinct();
                }

                return $query
                    ->filterByUsers($this)
                    ->count($con);
            }
        } else {
            return count($this->collAuthHistorys);
        }
    }

    /**
     * Method called to associate a AuthHistory object to this object
     * through the AuthHistory foreign key attribute.
     *
     * @param    AuthHistory $l AuthHistory
     * @return Users The current object (for fluent API support)
     */
    public function addAuthHistory(AuthHistory $l)
    {
        if ($this->collAuthHistorys === null) {
            $this->initAuthHistorys();
            $this->collAuthHistorysPartial = true;
        }
        if (!$this->collAuthHistorys->contains($l)) { // only add it if the **same** object is not already associated
            $this->doAddAuthHistory($l);
        }

        return $this;
    }

    /**
     * @param	AuthHistory $authHistory The authHistory object to add.
     */
    protected function doAddAuthHistory($authHistory)
    {
        $this->collAuthHistorys[]= $authHistory;
        $authHistory->setUsers($this);
    }

    /**
     * @param	AuthHistory $authHistory The authHistory object to remove.
     */
    public function removeAuthHistory($authHistory)
    {
        if ($this->getAuthHistorys()->contains($authHistory)) {
            $this->collAuthHistorys->remove($this->collAuthHistorys->search($authHistory));
            if (null === $this->authHistorysScheduledForDeletion) {
                $this->authHistorysScheduledForDeletion = clone $this->collAuthHistorys;
                $this->authHistorysScheduledForDeletion->clear();
            }
            $this->authHistorysScheduledForDeletion[]= $authHistory;
            $authHistory->setUsers(null);
        }
    }

    /**
     * Clears out the collUserPulpits collection
     *
     * This does not modify the database; however, it will remove any associated objects, causing
     * them to be refetched by subsequent calls to accessor method.
     *
     * @return void
     * @see        addUserPulpits()
     */
    public function clearUserPulpits()
    {
        $this->collUserPulpits = null; // important to set this to null since that means it is uninitialized
        $this->collUserPulpitsPartial = null;
    }

    /**
     * reset is the collUserPulpits collection loaded partially
     *
     * @return void
     */
    public function resetPartialUserPulpits($v = true)
    {
        $this->collUserPulpitsPartial = $v;
    }

    /**
     * Initializes the collUserPulpits collection.
     *
     * By default this just sets the collUserPulpits collection to an empty array (like clearcollUserPulpits());
     * however, you may wish to override this method in your stub class to provide setting appropriate
     * to your application -- for example, setting the initial array to the values stored in database.
     *
     * @param boolean $overrideExisting If set to true, the method call initializes
     *                                        the collection even if it is not empty
     *
     * @return void
     */
    public function initUserPulpits($overrideExisting = true)
    {
        if (null !== $this->collUserPulpits && !$overrideExisting) {
            return;
        }
        $this->collUserPulpits = new PropelObjectCollection();
        $this->collUserPulpits->setModel('UserPulpit');
    }

    /**
     * Gets an array of UserPulpit objects which contain a foreign key that references this object.
     *
     * If the $criteria is not null, it is used to always fetch the results from the database.
     * Otherwise the results are fetched from the database the first time, then cached.
     * Next time the same method is called without $criteria, the cached collection is returned.
     * If this Users is new, it will return
     * an empty collection or the current collection; the criteria is ignored on a new object.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @return PropelObjectCollection|UserPulpit[] List of UserPulpit objects
     * @throws PropelException
     */
    public function getUserPulpits($criteria = null, PropelPDO $con = null)
    {
        $partial = $this->collUserPulpitsPartial && !$this->isNew();
        if (null === $this->collUserPulpits || null !== $criteria  || $partial) {
            if ($this->isNew() && null === $this->collUserPulpits) {
                // return empty collection
                $this->initUserPulpits();
            } else {
                $collUserPulpits = UserPulpitQuery::create(null, $criteria)
                    ->filterByUsers($this)
                    ->find($con);
                if (null !== $criteria) {
                    if (false !== $this->collUserPulpitsPartial && count($collUserPulpits)) {
                      $this->initUserPulpits(false);

                      foreach($collUserPulpits as $obj) {
                        if (false == $this->collUserPulpits->contains($obj)) {
                          $this->collUserPulpits->append($obj);
                        }
                      }

                      $this->collUserPulpitsPartial = true;
                    }

                    return $collUserPulpits;
                }

                if($partial && $this->collUserPulpits) {
                    foreach($this->collUserPulpits as $obj) {
                        if($obj->isNew()) {
                            $collUserPulpits[] = $obj;
                        }
                    }
                }

                $this->collUserPulpits = $collUserPulpits;
                $this->collUserPulpitsPartial = false;
            }
        }

        return $this->collUserPulpits;
    }

    /**
     * Sets a collection of UserPulpit objects related by a one-to-many relationship
     * to the current object.
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
     * and new objects from the given Propel collection.
     *
     * @param PropelCollection $userPulpits A Propel collection.
     * @param PropelPDO $con Optional connection object
     */
    public function setUserPulpits(PropelCollection $userPulpits, PropelPDO $con = null)
    {
        $this->userPulpitsScheduledForDeletion = $this->getUserPulpits(new Criteria(), $con)->diff($userPulpits);

        foreach ($this->userPulpitsScheduledForDeletion as $userPulpitRemoved) {
            $userPulpitRemoved->setUsers(null);
        }

        $this->collUserPulpits = null;
        foreach ($userPulpits as $userPulpit) {
            $this->addUserPulpit($userPulpit);
        }

        $this->collUserPulpits = $userPulpits;
        $this->collUserPulpitsPartial = false;
    }

    /**
     * Returns the number of related UserPulpit objects.
     *
     * @param Criteria $criteria
     * @param boolean $distinct
     * @param PropelPDO $con
     * @return int             Count of related UserPulpit objects.
     * @throws PropelException
     */
    public function countUserPulpits(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    {
        $partial = $this->collUserPulpitsPartial && !$this->isNew();
        if (null === $this->collUserPulpits || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collUserPulpits) {
                return 0;
            } else {
                if($partial && !$criteria) {
                    return count($this->getUserPulpits());
                }
                $query = UserPulpitQuery::create(null, $criteria);
                if ($distinct) {
                    $query->distinct();
                }

                return $query
                    ->filterByUsers($this)
                    ->count($con);
            }
        } else {
            return count($this->collUserPulpits);
        }
    }

    /**
     * Method called to associate a UserPulpit object to this object
     * through the UserPulpit foreign key attribute.
     *
     * @param    UserPulpit $l UserPulpit
     * @return Users The current object (for fluent API support)
     */
    public function addUserPulpit(UserPulpit $l)
    {
        if ($this->collUserPulpits === null) {
            $this->initUserPulpits();
            $this->collUserPulpitsPartial = true;
        }
        if (!$this->collUserPulpits->contains($l)) { // only add it if the **same** object is not already associated
            $this->doAddUserPulpit($l);
        }

        return $this;
    }

    /**
     * @param	UserPulpit $userPulpit The userPulpit object to add.
     */
    protected function doAddUserPulpit($userPulpit)
    {
        $this->collUserPulpits[]= $userPulpit;
        $userPulpit->setUsers($this);
    }

    /**
     * @param	UserPulpit $userPulpit The userPulpit object to remove.
     */
    public function removeUserPulpit($userPulpit)
    {
        if ($this->getUserPulpits()->contains($userPulpit)) {
            $this->collUserPulpits->remove($this->collUserPulpits->search($userPulpit));
            if (null === $this->userPulpitsScheduledForDeletion) {
                $this->userPulpitsScheduledForDeletion = clone $this->collUserPulpits;
                $this->userPulpitsScheduledForDeletion->clear();
            }
            $this->userPulpitsScheduledForDeletion[]= $userPulpit;
            $userPulpit->setUsers(null);
        }
    }


    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Users is new, it will return
     * an empty collection; or if this Users has previously
     * been saved, it will retrieve related UserPulpits from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Users.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
     * @return PropelObjectCollection|UserPulpit[] List of UserPulpit objects
     */
    public function getUserPulpitsJoinApplications($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    {
        $query = UserPulpitQuery::create(null, $criteria);
        $query->joinWith('Applications', $join_behavior);

        return $this->getUserPulpits($query, $con);
    }

    /**
     * Clears out the collUserApplicationDatas collection
     *
     * This does not modify the database; however, it will remove any associated objects, causing
     * them to be refetched by subsequent calls to accessor method.
     *
     * @return void
     * @see        addUserApplicationDatas()
     */
    public function clearUserApplicationDatas()
    {
        $this->collUserApplicationDatas = null; // important to set this to null since that means it is uninitialized
        $this->collUserApplicationDatasPartial = null;
    }

    /**
     * reset is the collUserApplicationDatas collection loaded partially
     *
     * @return void
     */
    public function resetPartialUserApplicationDatas($v = true)
    {
        $this->collUserApplicationDatasPartial = $v;
    }

    /**
     * Initializes the collUserApplicationDatas collection.
     *
     * By default this just sets the collUserApplicationDatas collection to an empty array (like clearcollUserApplicationDatas());
     * however, you may wish to override this method in your stub class to provide setting appropriate
     * to your application -- for example, setting the initial array to the values stored in database.
     *
     * @param boolean $overrideExisting If set to true, the method call initializes
     *                                        the collection even if it is not empty
     *
     * @return void
     */
    public function initUserApplicationDatas($overrideExisting = true)
    {
        if (null !== $this->collUserApplicationDatas && !$overrideExisting) {
            return;
        }
        $this->collUserApplicationDatas = new PropelObjectCollection();
        $this->collUserApplicationDatas->setModel('UserApplicationData');
    }

    /**
     * Gets an array of UserApplicationData objects which contain a foreign key that references this object.
     *
     * If the $criteria is not null, it is used to always fetch the results from the database.
     * Otherwise the results are fetched from the database the first time, then cached.
     * Next time the same method is called without $criteria, the cached collection is returned.
     * If this Users is new, it will return
     * an empty collection or the current collection; the criteria is ignored on a new object.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @return PropelObjectCollection|UserApplicationData[] List of UserApplicationData objects
     * @throws PropelException
     */
    public function getUserApplicationDatas($criteria = null, PropelPDO $con = null)
    {
        $partial = $this->collUserApplicationDatasPartial && !$this->isNew();
        if (null === $this->collUserApplicationDatas || null !== $criteria  || $partial) {
            if ($this->isNew() && null === $this->collUserApplicationDatas) {
                // return empty collection
                $this->initUserApplicationDatas();
            } else {
                $collUserApplicationDatas = UserApplicationDataQuery::create(null, $criteria)
                    ->filterByUsers($this)
                    ->find($con);
                if (null !== $criteria) {
                    if (false !== $this->collUserApplicationDatasPartial && count($collUserApplicationDatas)) {
                      $this->initUserApplicationDatas(false);

                      foreach($collUserApplicationDatas as $obj) {
                        if (false == $this->collUserApplicationDatas->contains($obj)) {
                          $this->collUserApplicationDatas->append($obj);
                        }
                      }

                      $this->collUserApplicationDatasPartial = true;
                    }

                    return $collUserApplicationDatas;
                }

                if($partial && $this->collUserApplicationDatas) {
                    foreach($this->collUserApplicationDatas as $obj) {
                        if($obj->isNew()) {
                            $collUserApplicationDatas[] = $obj;
                        }
                    }
                }

                $this->collUserApplicationDatas = $collUserApplicationDatas;
                $this->collUserApplicationDatasPartial = false;
            }
        }

        return $this->collUserApplicationDatas;
    }

    /**
     * Sets a collection of UserApplicationData objects related by a one-to-many relationship
     * to the current object.
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
     * and new objects from the given Propel collection.
     *
     * @param PropelCollection $userApplicationDatas A Propel collection.
     * @param PropelPDO $con Optional connection object
     */
    public function setUserApplicationDatas(PropelCollection $userApplicationDatas, PropelPDO $con = null)
    {
        $this->userApplicationDatasScheduledForDeletion = $this->getUserApplicationDatas(new Criteria(), $con)->diff($userApplicationDatas);

        foreach ($this->userApplicationDatasScheduledForDeletion as $userApplicationDataRemoved) {
            $userApplicationDataRemoved->setUsers(null);
        }

        $this->collUserApplicationDatas = null;
        foreach ($userApplicationDatas as $userApplicationData) {
            $this->addUserApplicationData($userApplicationData);
        }

        $this->collUserApplicationDatas = $userApplicationDatas;
        $this->collUserApplicationDatasPartial = false;
    }

    /**
     * Returns the number of related UserApplicationData objects.
     *
     * @param Criteria $criteria
     * @param boolean $distinct
     * @param PropelPDO $con
     * @return int             Count of related UserApplicationData objects.
     * @throws PropelException
     */
    public function countUserApplicationDatas(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    {
        $partial = $this->collUserApplicationDatasPartial && !$this->isNew();
        if (null === $this->collUserApplicationDatas || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collUserApplicationDatas) {
                return 0;
            } else {
                if($partial && !$criteria) {
                    return count($this->getUserApplicationDatas());
                }
                $query = UserApplicationDataQuery::create(null, $criteria);
                if ($distinct) {
                    $query->distinct();
                }

                return $query
                    ->filterByUsers($this)
                    ->count($con);
            }
        } else {
            return count($this->collUserApplicationDatas);
        }
    }

    /**
     * Method called to associate a UserApplicationData object to this object
     * through the UserApplicationData foreign key attribute.
     *
     * @param    UserApplicationData $l UserApplicationData
     * @return Users The current object (for fluent API support)
     */
    public function addUserApplicationData(UserApplicationData $l)
    {
        if ($this->collUserApplicationDatas === null) {
            $this->initUserApplicationDatas();
            $this->collUserApplicationDatasPartial = true;
        }
        if (!$this->collUserApplicationDatas->contains($l)) { // only add it if the **same** object is not already associated
            $this->doAddUserApplicationData($l);
        }

        return $this;
    }

    /**
     * @param	UserApplicationData $userApplicationData The userApplicationData object to add.
     */
    protected function doAddUserApplicationData($userApplicationData)
    {
        $this->collUserApplicationDatas[]= $userApplicationData;
        $userApplicationData->setUsers($this);
    }

    /**
     * @param	UserApplicationData $userApplicationData The userApplicationData object to remove.
     */
    public function removeUserApplicationData($userApplicationData)
    {
        if ($this->getUserApplicationDatas()->contains($userApplicationData)) {
            $this->collUserApplicationDatas->remove($this->collUserApplicationDatas->search($userApplicationData));
            if (null === $this->userApplicationDatasScheduledForDeletion) {
                $this->userApplicationDatasScheduledForDeletion = clone $this->collUserApplicationDatas;
                $this->userApplicationDatasScheduledForDeletion->clear();
            }
            $this->userApplicationDatasScheduledForDeletion[]= $userApplicationData;
            $userApplicationData->setUsers(null);
        }
    }


    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Users is new, it will return
     * an empty collection; or if this Users has previously
     * been saved, it will retrieve related UserApplicationDatas from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Users.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
     * @return PropelObjectCollection|UserApplicationData[] List of UserApplicationData objects
     */
    public function getUserApplicationDatasJoinApplicationDataDefs($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    {
        $query = UserApplicationDataQuery::create(null, $criteria);
        $query->joinWith('ApplicationDataDefs', $join_behavior);

        return $this->getUserApplicationDatas($query, $con);
    }

    /**
     * Clears the current object and sets all attributes to their default values
     */
    public function clear()
    {
        $this->id = null;
        $this->user_group_id = null;
        $this->fname = null;
        $this->lname = null;
        $this->email = null;
        $this->optional_email = null;
        $this->company = null;
        $this->department = null;
        $this->phone = null;
        $this->mobile = null;
        $this->photo = null;
        $this->ad_login = null;
        $this->role = null;
        $this->deleted = null;
        $this->active = null;
        $this->last_modified = null;
        $this->created = null;
        $this->alreadyInSave = false;
        $this->alreadyInValidation = false;
        $this->clearAllReferences();
        $this->applyDefaultValues();
        $this->resetModified();
        $this->setNew(true);
        $this->setDeleted(false);
    }

    /**
     * Resets all references to other model objects or collections of model objects.
     *
     * This method is a user-space workaround for PHP's inability to garbage collect
     * objects with circular references (even in PHP 5.3). This is currently necessary
     * when using Propel in certain daemon or large-volumne/high-memory operations.
     *
     * @param boolean $deep Whether to also clear the references on all referrer objects.
     */
    public function clearAllReferences($deep = false)
    {
        if ($deep) {
            if ($this->collAuthHistorys) {
                foreach ($this->collAuthHistorys as $o) {
                    $o->clearAllReferences($deep);
                }
            }
            if ($this->collUserPulpits) {
                foreach ($this->collUserPulpits as $o) {
                    $o->clearAllReferences($deep);
                }
            }
            if ($this->collUserApplicationDatas) {
                foreach ($this->collUserApplicationDatas as $o) {
                    $o->clearAllReferences($deep);
                }
            }
        } // if ($deep)

        if ($this->collAuthHistorys instanceof PropelCollection) {
            $this->collAuthHistorys->clearIterator();
        }
        $this->collAuthHistorys = null;
        if ($this->collUserPulpits instanceof PropelCollection) {
            $this->collUserPulpits->clearIterator();
        }
        $this->collUserPulpits = null;
        if ($this->collUserApplicationDatas instanceof PropelCollection) {
            $this->collUserApplicationDatas->clearIterator();
        }
        $this->collUserApplicationDatas = null;
        $this->aUserGroups = null;
    }

    /**
     * return the string representation of this object
     *
     * @return string
     */
    public function __toString()
    {
        return (string) $this->exportTo(UsersPeer::DEFAULT_STRING_FORMAT);
    }

    /**
     * return true is the object is in saving state
     *
     * @return boolean
     */
    public function isAlreadyInSave()
    {
        return $this->alreadyInSave;
    }

}
